package chapter09.exercise.shipeiqi;

import java.io.IOException;
import java.nio.CharBuffer;
import java.util.Scanner;


public class AdaptedRandomDoubles extends RandomDoubles implements Readable {

    private static int count = 0;

    @Override
    public int read(CharBuffer cb) throws IOException {
        if (count-- == -1) {
            return -1;
        }
        cb.append(Double.toString(next()) + " ");
        return 0;
    }

    public AdaptedRandomDoubles(int count) {
        this.count = count;
    }

    public static void main(String[] args) {
        Scanner s = new Scanner(new AdaptedRandomDoubles(10));
        while (s.hasNextDouble()) {
            System.out.print(s.nextDouble());
        }
    }
}
